
package cn.edu.scau.cmi.hombio.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllMedicineSuppliers", query = "select myMedicineSupplier from MedicineSupplier myMedicineSupplier"),
		@NamedQuery(name = "findMedicineSupplierById", query = "select myMedicineSupplier from MedicineSupplier myMedicineSupplier where myMedicineSupplier.id = ?1"),
		@NamedQuery(name = "findMedicineSupplierByPrimaryKey", query = "select myMedicineSupplier from MedicineSupplier myMedicineSupplier where myMedicineSupplier.id = ?1") })

@Table(catalog = "pig", name = "medicine_supplier")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain", name = "MedicineSupplier")
@XmlRootElement(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain")
public class MedicineSupplier implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "Id", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@Id @GeneratedValue
	@XmlElement
	Integer id;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "Medicine", referencedColumnName = "Id") })
	@XmlTransient
	Medicine medicine;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "Supplier", referencedColumnName = "id") })
	@XmlTransient
	Supplier supplier;
	/**
	 */
	@OneToMany(mappedBy = "medicineSupplier", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.MedicinePrice> medicinePrices;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setMedicine(Medicine medicine) {
		this.medicine = medicine;
	}

	/**
	 */
	@JsonIgnore
	public Medicine getMedicine() {
		return medicine;
	}

	/**
	 */
	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	/**
	 */
	@JsonIgnore
	public Supplier getSupplier() {
		return supplier;
	}

	/**
	 */
	public void setMedicinePrices(Set<MedicinePrice> medicinePrices) {
		this.medicinePrices = medicinePrices;
	}

	/**
	 */
	@JsonIgnore
	public Set<MedicinePrice> getMedicinePrices() {
		if (medicinePrices == null) {
			medicinePrices = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.MedicinePrice>();
		}
		return medicinePrices;
	}

	/**
	 */
	public MedicineSupplier() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(MedicineSupplier that) {
		setId(that.getId());
		setMedicine(that.getMedicine());
		setSupplier(that.getSupplier());
		setMedicinePrices(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.MedicinePrice>(that.getMedicinePrices()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof MedicineSupplier))
			return false;
		MedicineSupplier equalCheck = (MedicineSupplier) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
